<template>
  <view class="index">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <!-- <view class="jtop_l" @tap="navigateBack">关闭</view> -->
      <view class="jtop_c">新增日志详情</view>
      <view class="jtop_r"  :style="{ opacity: name ? '1' : '.6' }" @click="jsave">确定</view>
    </view>
    <view class="tophr"></view>

    <view class="addb">
      <view class="addb_1">
        日期：{{ jt }} {{ xq }}<br />
        天气：{{ top_tq }}<br />
        风力：{{ top_fl }}<br />
        温度：{{ top_wd }}<br />
      </view>
    </view>

    <view class="addb">
      <view class="addb_1">
        项目编号：{{ top_bh }}<br />
        项目名称：{{ top_parameter }}<br />
      </view>
    </view>

    <view class="addb">
      <view class="addi2">
        <text>施工部位</text>
        <input
          type="text"
          placeholder="请输入施工部位"
          :value="name"
          @input="onKeyInput_o"
          placeholder-style="color:#CCCCCC"
        />
      </view>

      <view class="addi2">
        <text>出勤人数</text>
        <input
          type="number"
          placeholder="请输入出勤人数"
          :value="number"
          @input="onKeyInput_c"
          placeholder-style="color:#CCCCCC"
        />
      </view>
      <view class="addi2 noborder">
        <text>操作负责人</text>
        <input
          type="text"
          placeholder="请输入操作负责人"
          :value="leader"
          @input="onKeyInput_f"
          placeholder-style="color:#CCCCCC"
        />
      </view>
    </view>

    <view class="addb">
      <view class="addi2 addi3">
        <text>工作内容</text>
        <textarea
        auto-height="true"
        style="min-height: 150rpx;"
        maxlength="-1"
          placeholder-style="color:#CCCCCC"
          placeholder="请输入工作内容"
          :value="content"
          @input="onKeyInput_t"
        />
      </view>
    </view>

    <view class="addi">
      <text>拍照上传</text>
      <view class="att">
        <view v-for="(item, index) in jimg" :key="item.id">
          <image class="at" :src="item" @longpress="logoTime(index)"></image>
        </view>

        <image
          src="../../static/img/index/new/at.png"
          mode=""
          class="at"
          @tap="changeAvatar()"
        ></image>
      </view>
    </view>

    <!-- 弹出层 -->
    <view :class="[ashowpop2 ? 'tc' : 'tc hide']">
      <view class="jtop_bj"></view>

      <view class="tc_fbox">
        <view class="tc_fbox_bt2" @click="btTC_jdel">
          删除
        </view>
        <view class="tc_fbox_bt" @click="btTCC">
          取消
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      ashowpop_jrename: false,
      ashowpop_jdel: false,
      ashowpopT: false,
      bj: false,
      yd: false,
      jt: '',
      xq: '',
      date: '',
      city: '',
      tq: '',
      wd: '',

      photo: '',
      number: '',
      name: '',
      leader: '',
      content: '',
      jimg: [],

      ashowpop2: false,
      top_tq: '',
      top_fl: '',
      top_wd: '',
      top_bh: uni.getStorageSync('dqfull_name').corpId,
      top_parameter: uni.getStorageSync('dqfull_name').name,
    };
  },

  onLoad() {
    uni.getLocation({
      type: 'wgs84',
      success: function(res) {
        console.log('当前位置的经度：' + res.longitude);
        console.log('当前位置的纬度：' + res.latitude);
        console.log('2222当前位置的纬度：' + res.address);
        this.address = res.address.city;
      },
      fail: e => {
        console.log(e);
      },
    });

    this.jt = uni.getStorageSync('jt');

    this.xq = uni.getStorageSync('week');
    this.adate = uni.getStorageSync('rq');
    var jd = {};
    jd.date = this.adate;
    if (this.address) {
      jd.city = this.address;
    } else {
      jd.city = '苏州市';
    }

    console.log(jd);

    request({
      url: `/modor/v1/common/weather`,
      data: jd,

      method: 'GET',
      success: openIdRes => {
        if (openIdRes.data.success == true) {
          console.log('1232', openIdRes);

          this.tq = openIdRes.data.data.weather;
          this.wd = openIdRes.data.data.temperature;

          // uni.navigateBack()
        } else {
          console.log('12321111', openIdRes);
          this.repeat_click = true;
          uni.showToast({
            title: openIdRes.data.msg,
            icon: 'none',
          });
          this.isLoading = false;
        }
      },
      fail: () => {
        this.repeat_click = true;
        uni.showToast({
          title: '服务器开小差，请稍后~',
          icon: 'none',
        });
        return false;
      },
    });
  },

  methods: {
    jsave() {
      if (!this.repeat_click) {
        return;
      }
      this.repeat_click = false;

      request({
        url: `/modor/v1/project/${uni.getStorageSync('dqfull_name').id}/construction`,
        data: {
          content: this.content,
          jobDate: this.adate,
          leader: this.leader,
          name: this.name,
          number: this.number,
          photo: this.jimg.join(','),
          temperature: this.wd,
          weather: this.tq,
        },

        method: 'POST',
        success: openIdRes => {
          console.log(openIdRes);
          if (openIdRes.data.success == true) {
            wx.showToast({
              title: '添加成功',
              icon: 'none',
              duration: 1000,
              success: function() {
                setTimeout(function() {
                  uni.navigateBack();
                }, 1500);
              },
            });

            // uni.navigateBack()
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: openIdRes.data.msg,
              icon: 'none',
            });
            this.isLoading = false;
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    changeAvatar() {
      var that = this;
      uni.chooseImage({
        count: 1, //默认9
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ['camera', 'album'], //从相册选择、摄像头
        success: function(res) {
          console.log(JSON.stringify(res.tempFilePaths, res.tempFiles[0]));

          that.sctp(res.tempFilePaths, res.tempFiles[0]);
        },
      });
    },

    sctp(a, b) {
      console.log(a);

      request({
        url: '/passport/v1/general/upload', //仅为示例，非真实的接口地址
        filePath: a[0],
        name: 'file',

        formData: {
          files: [{ uri: '' }],
        },
        success: res => {
          var cc = JSON.parse(res.data);
          console.log('上传图片', cc);

          if (cc.code == 200) {
            var dd = this.jimg;
            dd.push(cc.data.url + '/' + als.dir + g_object_name);
            this.jimg = dd;
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: cc.message,
              icon: 'none',
            });
          }
        },
      });
    },

    btTC_jdel() {
      var ax = this.jimg;
      ax.splice(this.scdtp, 1);

      console.log('ax1111', ax);

      this.jimg = ax;
      console.log('ax222', this.jimg);
      this.ashowpop2 = false;
    },

    btTCC(e) {
      this.ashowpop2 = !this.ashowpop2;
    },

    logoTime(e) {
      console.log(e);
      this.scdtp = e;
      this.ashowpop2 = true;
    },
    onKeyInput_o: function(event) {
      this.name = event.detail.value;
    },
    onKeyInput_t: function(event) {
      this.content = event.detail.value;
    },
    onKeyInput_c: function(event) {
      this.number = event.detail.value;
    },
    onKeyInput_f: function(event) {
      this.leader = event.detail.value;
    },

    // 跳转
    jshow_pop() {
      this.ashowpop = !this.ashowpop;
    },
    btTC2() {
      uni.navigateTo({
        url: '../main/work_add',
      });
    },

    navigateBack() {
      uni.navigateBack();
    },
  },
  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
};
</script>

<style>
.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}

.at {
  width: 160rpx;
  height: 160rpx;
  display: block;
  float: left;
  margin: 0rpx 0 0 0;
}
.att {
  width: 720rpx;
  margin: 0 0 30rpx 30rpx;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
}
.att image {
  margin: 0 20rpx 20rpx 0;
}

.addb_1 {
  width: 720rpx;
  margin: 20rpx 30rpx 20rpx 30rpx;
  font-size: 32rpx;
  line-height: 60rpx;
  color: #000000;
  height: auto;
  display: block;
  float: left;
}
.addb_2 {
  width: 720rpx;
  margin: 0rpx 30rpx 20rpx 30rpx;
  font-size: 32rpx;
  line-height: 4r0px;
  color: #666666;
  height: auto;
  display: block;
  float: left;
}

.ptt {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  margin: 20rpx 0 0;
}
.pttl {
  width: 84rpx;
  height: 84rpx;
  display: block;
  float: left;
  margin: 18rpx 20rpx 18rpx 30rpx;
}
.pttr {
  width: 400rpx;
  height: 84rpx;
  display: block;
  float: left;
  margin: 18rpx 0rpx 0rpx 0rpx;
}
.pttrt {
  width: 100%;
  height: 42rpx;
  line-height: 42rpx;
  display: block;
  float: left;
  font-size: 34rpx;
  color: #000000;
}
.pttrf {
  width: 100%;
  height: 42rpx;
  line-height: 42rpx;
  display: block;
  float: left;
  font-size: 24rpx;
  color: #999999;
}
.pttjt {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 48rpx 30rpx 0 30rpx;
}
.ptf {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  margin: 20rpx 0 0;
}
.ptft {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 90rpx;
  display: block;
  float: left;
  background: #ffffff;
}
.ptft image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 21rpx 20rpx 0 0rpx;
}
.ptft text {
  width: auto;
  height: 48rpx;
  display: block;
  float: left;
  margin: 21rpx 20rpx 0 0rpx;
  font-size: 34rpx;
  line-height: 48rpx;
  color: #000000;
}

.addi2 {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 90rpx;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.addi {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  box-shadow: inset 0px 1px 0px #dddddd, inset 0px -1px 0px #dddddd;
  margin: 20rpx 0 0;
}
.addi2 text {
  width: 200rpx;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
  margin: 0 0 0 0rpx;
}

.addi text {
  width: 200rpx;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
  margin: 0 0 0 30rpx;
}
.addi input,
.addi2 input {
  width: auto;
  height: 50rpx;
  display: block;
  float: left;
  margin: 20rpx 30rpx 0 0;
  text-align: left;
  line-height: 50rpx;
  font-size: 34rpx;
  color: #000000;
}
.addb {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border: 1px solid #dddddd;
  border-left: 0;
  border-right: 0;
  margin: 20rpx 0 0;
}
.addbi {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: 90rpx;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.addb .addbi:last-child {
  border: none;
}
.addbi .addbil {
  width: 200rpx;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 34rpx;
  color: #000000;
}
.addbi .addbir {
  width: auto;
  height: 90rpx;
  display: block;
  float: left;
  line-height: 90rpx;
  font-size: 32rpx;
  color: #000000;
}
.addbi image {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 33rpx 30rpx 0 30rpx;
}
.addi textarea {
  width: 690rpx;
  height: 150rpx;
  display: block;
  float: left;
  margin: 0rpx 30rpx 20rpx;
  text-align: left;
  line-height: 40rpx;
  font-size: 34rpx;
  color: #000000;
}

.addi3 {
  width: 720rpx;
  margin: 0 0 0 30rpx;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
}
.addi3 textarea {
  width: 720rpx;
  height: 150rpx;
  display: block;
  float: left;
  margin: 10rpx 30rpx 20rpx 0;
  text-align: left;
  line-height: 40rpx;
  font-size: 34rpx;
  color: #000000;
}

.index {
  background: rgb(242, 242, 242);
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}
.jtop_r {
  width: auto;
  height: 88rpx;
  display: block;
  float: right;
  margin: 0rpx 20rpx 0 0;
  line-height: 88rpx;
  font-size: 32rpx;
  color: #000000;
  color: #256aff;
}
.doc_b22 {
  opacity: 0.5;
}

.nd {
  width: 735rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 0 0 0rpx;
}
.nd_bt {
  width: auto;
  height: 48rpx;
  display: block;
  float: right;
  border: 1px solid #dddddd;
  border-radius: 24rpx;
  margin: 40rpx 0 40rpx 30rpx;
}
.nd_bt text {
  width: auto;
  height: 48rpx;
  display: block;
  float: left;
  margin: 0 7rpx 0 18rpx;
  line-height: 48rpx;
  color: #666666;
  font-size: 24rpx;
}
.nd_bt image {
  width: 13rpx;
  height: 8rpx;
  display: block;
  float: left;
  margin: 21rpx 14rpx 0 0;
}

.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
}
.tc_fbox_bt {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 20rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #f2f2f2;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10001;
}
.tc_fbox_bt2 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 0rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox_bt3 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-bottom: 1px solid #dddddd;
  background: #ffffff;
}
</style>
